package cn.kai.ums.service.impl;

import cn.kai.ums.tools.JWTtools;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kai.ums.model.UmsUser;
import cn.kai.ums.service.UmsUserService;
import cn.kai.ums.mapper.UmsUserMapper;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser>
    implements UmsUserService{

    @Autowired
    private UmsUserMapper umsUserMapper;

    @Override
    public String checklogin(String userName, String userPwd) {
        String pwd =String.valueOf(new SimpleHash("MD5",userPwd,userName,1024));
        UmsUser user = umsUserMapper.checklogin(userName,pwd);
        if(user==null){
            return "0";
        }else {
            if(user.getUserState()==0){
                return "-1";
            }else {
                String token = JWTtools.geneJsonWebToken(user);
                return token;
            }
        }
    }

    @Override
    public UmsUser getOneByname(String no) {
        return umsUserMapper.getOneByname(no);
    }
}




